package org.jeecg.modules.api.xxApi.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.apiacl.controller.ApiAuthorizeController;
import org.jeecg.modules.xxgx.hzsqgl.dto.HzxxbDto;
import org.jeecg.modules.xxgx.hzsqgl.dto.QueryHzxxbDto;
import org.jeecg.modules.xxgx.hzsqgl.service.ICsXxApiHzxxbService;
import org.jeecg.modules.xxgx.hzsqgl.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Description: 销项接口管理: 数电票相关
 * @Author: jeecg-boot
 * @Date: 2023-08-02
 * @Version: V1.0
 */
@ApiSort(value = 2)
@Api(tags = "销项接口管理")
@RestController
@RequestMapping(CommonConstant.API + "/xxApi")
@Slf4j
public class DigitalInvoiceController extends ApiAuthorizeController {

    @Autowired
    private ICsXxApiHzxxbService iCsXxApiHzxxbService;


    @AutoLog(value = "红字信息表申请")
    @ApiOperation(value = "红字信息表申请", notes = "数电票接口管理-红字信息表申请",position = 12)
    @PostMapping(value = "/hzxxbsq")
    public Result<HzxxbDto> hzxxbsq(@RequestBody @Valid XxApiHzxxbsqParam param, BindingResult bindingResult) {
        StringBuilder errMsg = new StringBuilder();
        if (bindingResult.hasErrors()) {
            List<ObjectError> allErrors = bindingResult.getAllErrors();
            for (ObjectError objectError : allErrors) {
                String defaultMessage = objectError.getDefaultMessage();
                errMsg.append(defaultMessage).append(",");
            }
        }
        if(errMsg.length() > 0){
            throw new JeecgBootException(errMsg.toString());
        }
        return iCsXxApiHzxxbService.hzxxbsq(param);
    }

    @AutoLog(value = "红字信息表撤销")
    @ApiOperation(value = "红字信息表撤销", notes = "数电票接口管理-红字信息表撤销",position = 13)
    @PostMapping(value = "/hzxxbcx")
    public Result<String> hzxxbcx(@RequestBody @Valid XxApiHzxxbcxParam param, BindingResult bindingResult) {
        StringBuilder errMsg = new StringBuilder();
        if (bindingResult.hasErrors()) {
            List<ObjectError> allErrors = bindingResult.getAllErrors();
            for (ObjectError objectError : allErrors) {
                String defaultMessage = objectError.getDefaultMessage();
                errMsg.append(defaultMessage).append(",");
            }
        }
        if(errMsg.length() > 0){
            throw new JeecgBootException(errMsg.toString());
        }
        return iCsXxApiHzxxbService.hzxxbcx(param);
    }

    @AutoLog(value = "红字信息表同步")
    @ApiOperation(value = "红字信息表同步", notes = "数电票接口管理-红字信息表同步",position = 14)
    @PostMapping(value = "/hzxxbtb")
    public Result<String> hzxxbtb(@RequestBody @Valid XxApiHzxxbtbParam param, BindingResult bindingResult) {
        StringBuilder errMsg = new StringBuilder();
        if (bindingResult.hasErrors()) {
            List<ObjectError> allErrors = bindingResult.getAllErrors();
            for (ObjectError objectError : allErrors) {
                String defaultMessage = objectError.getDefaultMessage();
                errMsg.append(defaultMessage).append(",");
            }
        }
        if(errMsg.length() > 0){
            throw new JeecgBootException(errMsg.toString());
        }
        return iCsXxApiHzxxbService.hzxxbtb(param);
    }

    @AutoLog(value = "红字信息表查询")
    @ApiOperation(value = "红字信息表查询", notes = "数电票接口管理-红字信息表查询",position = 15)
    @PostMapping(value = "/queryhzxxb")
    public Result<List<QueryHzxxbDto>> queryhzxxb(@RequestBody @Valid XxApiQueryHzxxbParam param, BindingResult bindingResult) {
        StringBuilder errMsg = new StringBuilder();
        if (bindingResult.hasErrors()) {
            List<ObjectError> allErrors = bindingResult.getAllErrors();
            for (ObjectError objectError : allErrors) {
                String defaultMessage = objectError.getDefaultMessage();
                errMsg.append(defaultMessage).append(",");
            }
        }
        if(errMsg.length() > 0){
            throw new JeecgBootException(errMsg.toString());
        }
        return iCsXxApiHzxxbService.queryhzxxb(param);
    }

    @AutoLog(value = "红字信息表确认")
    @ApiOperation(value = "红字信息表确认", notes = "数电票接口管理-红字信息表确认",position = 16)
    @PostMapping(value = "/hzxxbqr")
    public Result<String> hzxxbqr(@RequestBody @Valid XxApiHzxxbqrParam param, BindingResult bindingResult) {
        StringBuilder errMsg = new StringBuilder();
        if (bindingResult.hasErrors()) {
            List<ObjectError> allErrors = bindingResult.getAllErrors();
            for (ObjectError objectError : allErrors) {
                String defaultMessage = objectError.getDefaultMessage();
                errMsg.append(defaultMessage).append(",");
            }
        }
        if(errMsg.length() > 0){
            throw new JeecgBootException(errMsg.toString());
        }
        return iCsXxApiHzxxbService.hzxxbqr(param);
    }
}
